<?php
namespace app\admin\model;
use think\Model;
class Course extends Model
{
    public function addCourseName($course_info)
    {
        $course = new Course;
        $course->course = $course_info['course'];
        $course->created = $course_info['created'];
        $course->save();
        return $course->id;
    }
    
    public function saveCourse(array $course_info)
    {
        $course_id = $course_info['id'];
        unset($course_info['id']);
        $course = new Course;
        $result = $course->save($course_info,['id'=>$course_id]);
        return $result;
        
    }
    
    public function saveCourseModule($course_module)
    {
        $courseModules  = new Coursemodules;
        if ($course_module['id'] == ''){
            $courseModules->course_module = $course_module['course_module'];
            $courseModules->created = time();
            $courseModules->save();
            $course_module_id = $courseModules->id;
        }else {
           $list = [
            'course_module' => $course_module['course_module'],
            'created' => time()
            ];
           $course_module_id = $course_module['id'];
           $courseModules->save($list,['id' => $course_module_id]);
        }
        if ($course_module_id == false){
            return false;
        }
        $list1 = array();
        foreach ($course_module['course'] as $k => $v){
            $course_tmp['id'] = $v['id'];
            $course_tmp['course'] = $v['course'];
            $course_tmp['parent_id'] = $course_module_id;
            array_push($list1, $course_tmp);
        }
        $result['course_module_id'] = $course_module_id;
        $course = new Course;
        $result['res'] = $course->saveAll($list1);
        return $result;
    }
}